package mk.jug.academy.preconditions;

import mk.jug.academy.exception.BusinessException;
import mk.jug.academy.model.Student;
import mk.jug.academy.model.status.StudentStatus;

import org.springframework.util.Assert;


/**
 * Class separating the concerns of checking preconditions for
 * regarding {@link Student} processes.
 * 
 * It is usually a Precondition <-> Service pair.
 *
 * @author Ice.Penov
 */
public final class StudentPreconditions {
	
	
	/** No instantiation. Static usage only */
	private StudentPreconditions() {;}

	public static void registerStudent(Student student) {
		Assert.notNull(student.getFirstName(), PreconditionExceptions.MISSING_FIRST_NAME);
		Assert.notNull(student.getLastName(), PreconditionExceptions.MISSING_LAST_NAME);
		Assert.notNull(student.getEmail(), PreconditionExceptions.MISSING_EMAIL);		
	}
	
	public static void approveRegistration(Student student) {
		if (!student.getStatus().equals(StudentStatus.SIGNED_UP)) {
			throw new BusinessException(ErrorCodes.ERROR_STUDENT_SIGNED_UP_STATE);
		}
		Assert.notNull(student, PreconditionExceptions.STUDENT_IS_NULL);
		Assert.notNull(student.getId(), PreconditionExceptions.ID_IS_NULL);		
	}
	
	public static void denyRegistration(Student student) {
		if (!student.getStatus().equals(StudentStatus.SIGNED_UP)) {
			throw new BusinessException(ErrorCodes.ERROR_STUDENT_SIGNED_UP_STATE);
		}
		Assert.notNull(student, PreconditionExceptions.STUDENT_IS_NULL);
		Assert.notNull(student.getId(), PreconditionExceptions.ID_IS_NULL);				
	}
	
}